package com.naodong.shenluntiku.mvp.view.fragment;

import android.os.Bundle;

import com.naodong.shenluntiku.R;
import com.naodong.shenluntiku.mvp.model.bean.Assessment;
import com.yatatsu.autobundle.AutoBundleField;

import me.shingohu.man.base.BaseMVPFragment;
import me.shingohu.man.di.component.AppComponent;

/**
 * Created by Administrator on 2017/5/24.
 */

public class AssessmentLastPagerFragment extends BaseMVPFragment {

    @AutoBundleField(required = false)
    Assessment assessment;

    @AutoBundleField(required = false)
    int lastPagerMode = -1;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    public static AssessmentLastPagerFragment getInstance(int lastPagerMode,Assessment assessment) {
        AssessmentLastPagerFragment fragmet = new AssessmentLastPagerFragment();
        fragmet.setAssessment(assessment);
        fragmet.setLastPagerMode(lastPagerMode);
        return fragmet;
    }

    public void setLastPagerMode(int lastPagerMode) {
        this.lastPagerMode = lastPagerMode;
    }

    public void updateLastPagerMode(int lastPagerMode) {
        if(this.lastPagerMode!=lastPagerMode){
            this.lastPagerMode = lastPagerMode;
            loadRootFragment();
        }
    }

    private void loadRootFragment(){
        if(lastPagerMode==1) {
            replaceLoadRootFragment(R.id.container,AssessmentAnswerSheetFragment.getInstance(assessment),false );
        }else if(lastPagerMode==3){
            replaceLoadRootFragment(R.id.container,AssessmentResultFragment.getInstance(assessment),false );
        }else if(lastPagerMode==5){
            replaceLoadRootFragment(R.id.container,GoonFragment.getInstance(),false);
        }
    }

    public void setAssessment(Assessment assessment) {
        this.assessment = assessment;
    }

    @Override
    protected void onViewCreated(Bundle savedInstanceState) {
        loadRootFragment();
    }

    @Override
    protected int layoutId() {
        return R.layout.f_assessment_lastpager;
    }
}
